from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from controllers.device_controller import router as device_router
from controllers.workflow_controller import router as workflow_router
from pathlib import Path
app = FastAPI(
    title="Device Control API",
    description="API for controlling Android devices",
    version="1.0.0"
)
# 挂载静态文件目录
static_dir = Path(__file__).parent / "static"
# 挂载静态文件目录
app.mount("/static", StaticFiles(directory=static_dir), name="static")
# 允许跨域请求
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

@app.get("/",description="test", tags=["root"])
async def root():
    return {"message": "Device Control API"}

app.include_router(device_router, prefix="/devices", tags=["devices"])
app.include_router(workflow_router, prefix="/workflows",tags=["workflows"])

# 启动时启动设备管理线程
def begin_work_thread():
    print("开始工作线程")

def end_work_thread():
    print("结束工作线程")
app.add_event_handler("startup", begin_work_thread)
app.add_event_handler("shutdown", end_work_thread)